package com.wc.算法提高课.C第三章_图论.无向图的双连通分量.矿场搭建;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/22 19:11
 * @description https://www.acwing.com/problem/content/398/
 */
public class Main {
    /**
     * 思路；无向图的双连通分量 + 割点<p>
     * 缩点内部没有割点, 那就缩点内部要有俩出口<p>
     * 缩点内部有 1 割点, 那就缩点内部要有 1 出口<p>
     * 缩点内部 > 1 割点, 他可以去其他的连通块中<p>
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010, M = N;
    static int[] h = new int[N], e = new int[M], ne = new int[M];
    static int[] dfn = new int[N], low = new int[N];
    static int[] stk = new int[N];
    static boolean[] cut = new boolean[N];
    static ArrayList<Integer>[] dcc = new ArrayList[N];
    static int idx = 1, dccCnt = 0, top = 0, root = 0, timestamp = 0;
    static int n, m;

    public static void main(String[] args) {
        int T = 1;
        for (int i = 0; i < N; i++) dcc[i] = new ArrayList<>();
        while ((m = sc.nextInt()) != 0) {
            Arrays.fill(h, 0);
            Arrays.fill(dfn, 0);
            Arrays.fill(cut, false);
            for (int i = 1; i <= dccCnt; i++) dcc[i].clear();
            idx = 1;
            n = dccCnt = top = timestamp = 0;
            while (m-- > 0) {
                int a = sc.nextInt(), b = sc.nextInt();
                add(a, b);
                add(b, a);
                n = Math.max(n, a);
                n = Math.max(n, b);
            }
            for (root = 1; root <= n; root++) {
                if (dfn[root] == 0) {
                    tarjan(root);
                }
            }
            int res = 0;
            long num = 1;
            for (int i = 1; i <= dccCnt; i++) {
                int size = dcc[dccCnt].size();
                int cnt = 0;
                for (int j = 0; j < size; j++) {
                    int point = dcc[i].get(j);
                    if (cut[point]) cnt++;
                }
                // 这个表示没有割点, 度为 0
                if (cnt == 0) {
                    // 连通块里面只有一个孤立点
                    if (size == 1) res++;
                    else {
                        res += 2;
                        num = num * size * (size - 1) / 2;
                    }
                    // 有一个割点, 度为 1
                } else if (cnt == 1) {
                    res++;
                    num *= size - 1;
                }
            }
            out.printf("Case %d: %d %d\n", T++, res, num);
        }
        out.flush();
    }

    static void tarjan(int u) {
        dfn[u] = low[u] = ++timestamp;
        stk[++top] = u;
        if (u == root && h[u] == 0) {
            ++dccCnt;
            dcc[dccCnt].add(u);
            return;
        }
        int cnt = 0;
        for (int i = h[u]; i > 0; i = ne[i]) {
            int j = e[i];
            if (dfn[j] == 0) {
                tarjan(j);
                low[u] = Math.min(low[u], low[j]);
                if (dfn[u] <= low[j]) {
                    cnt++;
                    if (u != root || cnt > 1) cut[u] = true;
                    ++dccCnt;
                    int y;
                    do {
                        y = stk[top--];
                        dcc[dccCnt].add(y);
                    } while (y != j);
                    dcc[dccCnt].add(u);
                }
            } else low[u] = Math.min(low[u], dfn[j]);
        }

    }

    static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
